<su-form action="<%= form_path([:admin, @role]) %>"
         method="post"
         :init-fields="{authenticity_token: '<%= form_authenticity_token %>'}">
  <input name="utf8" type="hidden" value="✓">
  <input type="hidden" name="_method" value="<%= form_method @role %>">

  <%= form_validate @role %>
  <su-input type="text" label='<%= t "activerecord.attributes.role.name" %>' autofocus required
            name="role[name]" value="<%= @role.name %>"></su-input>
  <su-input type="number" label='<%= t "activerecord.attributes.role.position" %>' name="role[position]" value="<%= @role.position %>"></su-input>

  <su-select label='<%= t 'activerecord.attributes.role.permissions' %>' required multiple
             name="role[permissions][]" :value="<%= @role.permissions.ids %>">
    <% permissions_groups.each do |group| %>
        <optgroup label="<%= group.name %>">
          <% group.permissions.each do |item| %>
              <option value="<%= item.id %>"><%= item.description %></option>
          <% end %>
        </optgroup>
    <% end %>
    <optgroup label="其他">
      <% Permission.all.where(group_id: nil).each do |item| %>
          <option value="<%= item.id %>"><%= item.description %></option>
      <% end %>
    </optgroup>
  </su-select>

  <div class="clearfix form-actions">
    <%= render partial: 'shared/form/new_actions', locals: {options: {back_url: admin_roles_path }} %>
  </div>
</su-form>